<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./js/jquery-2.1.0.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/Global.js"></script>
    <style>
        .wrap {
            padding: 20px;
            width: 100%;
            overflow: auto;
            box-sizing: border-box;
        }

        .select {
            height: 40px;
            padding: 20px 0;
            border-bottom: 1px solid #ccc;
            text-align: center;
        }

        .search {
            width: 200px;
            height: 38px;
            margin: 0 auto;
            display: inline-block;
            padding-top: 1px;

        }

        select {
            height: 36px;
            min-width: 80px;
        }

        .layui-input {
            border: 0;
            outline: none;
        }

        .btn {
            display: inline-block;

        }

        .next {
            text-align: center;
        }

        .layui-table td,
        .layui-table th {
            padding: 0;
            text-align: center;
            height: 36px;
            line-height: 36px;
            font-size: 14px;
        }

        .hanf {
            width: 49%;
        }

        .layui-input-block {
            margin-left: 0px;
            padding: 0 5px;
        }

        .control {
            min-width: 110px;
        }

        .num {
            min-width: 50px;
        }

        .top-nav {
            font-size: 14px;
            list-style: none;
            position: relative;
            display: none;
        }

        .winbody {
            width: 1200px;
            padding: 10px;
            display: none;
        }

        .ddpl,.pzhz {
            display: none;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div style="text-align: right;">
                <div class="layui-btn layui-btn-xs" onclick="xqList()">
                        需求汇总
                    </div>
            <div class="layui-btn layui-btn-xs" onclick="pzList()">
                品种汇总
            </div>
            <div class="layui-btn layui-btn-xs" onclick="ddList()">
                订单排列
            </div>
        </div>
        <table class="layui-table xuhz" lay-filter="table">
            <thead>
                <tr>
                    <th width="5%" class="num">序号</th>
                    <th width="15%">客户名称</th>
                    <th width="10%">订单日期</th>
                    <th width="10%">订单号</th>
                    <th width="7.5%">品名</th>
                    <th width="7.5%">规格</th>
                    <th width="7.5%">品牌</th>
                    <th width="7.5%">型号</th>
                    <th width="7.5%">产地</th>
                    <th width="7.5%">物料新旧</th>
                    <th width="5%">单位</th>
                    <th width="5%">需求量</th>
                    <th width="5%">业务经理</th>
                </tr>
            </thead>
            <tbody class="lists">

            </tbody>
        </table>
        <table class="layui-table ddpl">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>客户名称</th>
                    <th>订单日期</th>
                    <th>订单号</th>
                    <th>品名</th>
                    <th>品牌</th>
                    <th>规格</th>
                    <th>型号</th>
                    <th>产地</th>
                    <th>物料新旧</th>
                    <th>单位</th>
                    <th>需求数量</th>
                    <th>库存数量</th>
                    <th>预警数量</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody class="chukulist">
                <tr>
                    <td>1</td>
                    <td>金方舟长客服务中心</td>
                    <td>2018-09-11</td>
                    <td>CGDD180911002</td>
                    <td>电器-定位器</td>
                    <td>胎客</td>
                    <td>固定式</td>
                    <td>TM-CFQ-A</td>
                    <td>国产</td>
                    <td>旧物品</td>
                    <td>桶</td>
                    <td>1</td>
                    <td>0</td>
                    <td>0</td>
                    <td onclick="ckInfo()">销售出库</td>
                </tr>
            </tbody>
        </table>
        <table class="layui-table pzhz">
                <thead>
                        <tr>
                            <th>序号</th>
                            <th>品名</th>
                            <th>品牌</th>
                            <th>规格</th>
                            <th>型号</th>
                            <th>产地</th>
                            <th>物料新旧</th>
                            <th>单位</th>
                            <th>需求数量</th>
                            <th>库存数量</th>
                            <th>预警数量</th>
                            <th>订购数量</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="pzhzlist">
                           
                        </tr>
                    </tbody>
        </table>
    </div>
</body>
<script>
    // 
    let layer = ''
    layui.use('layer', function () {
        layer = layui.layer
    })
    function ckInfo() {
        window.location.href = './dingdanxiangqing.html'
    }
    function xqList() {
            $('.xuhz').show()
            $('.ddpl').hide()
            $('.pzhz').hide()
    }
    function pzList() {
            $('.xuhz').hide()
            $('.ddpl').hide()
            $('.pzhz').show()
    }
    function ddList() {
            $('.xuhz').hide()
            $('.ddpl').show()
            $('.pzhz').hide()
    }
    $.ajax({
        url:`${API}/erpOrderd/getOrderdMaterielPage?custId=${loadUserInfo.customer.id}`,
        type:'get',
        success: function (res) {
            let str = ''
            let arr = res.data.records.reverse()
            $.each(arr,function (i,json) {
                if(json) {
                    str += `<tr>
                        <td>${arr.length - i}</td>
                            <td>${json.orderdMateriels.materielName == null ? '' : json.orderdMateriels.materielName}</td>
                            <td>${json.orderdMateriels.materielBrand == null ? '' : json.orderdMateriels.materielBrand}</td>
                            <td>${json.orderdMateriels.materielSpecifications == null ? '' : json.orderdMateriels.materielSpecifications}</td>
                            <td>${json.orderdMateriels.materielModel == null ? '' : json.orderdMateriels.materielModel}</td>
                            <td>${json.orderdMateriels.materielPlace == null ? '' : json.orderdMateriels.materielPlace}</td>
                            <td>${json.orderdMateriels.materielState == null ? '' : json.orderdMateriels.materielState}</td>
                            <td>${json.orderdMateriels.materielUnit == null ? '' : json.orderdMateriels.materielUnit}</td>
                            <td>${json.orderdMateriels.materielAmount == null ? '' : json.orderdMateriels.materielAmount}</td>
                            <td>${json.orderdMateriels.workState == null ? '' : json.orderdMateriels.workState}</td>
                            <td>${json.wordState == null ? '' : json.wordState}</td>
                            <td>${json.wordState == null ? '' : json.wordState}</td>
                        </tr>`
                }
            })
            $('.pzhzlist').html(str)
        }
    })
    $.ajax({
        url: `${API}/erpOrderdMateriel/getOrderdMateriel?custId=${loadUserInfo.customer.id}`,
        type: 'get',
        success: function (res) {
            let arr = res.data
            let str = ''
            $.each(arr, function (i, n) {

                if (n) {
                    $.ajax({
                        url: `${API}/erpOrderd/getOrderdById?orderId=${n.id}`,
                        type: 'get',
                        async: false,
                        success: function (res) {
                            let json = res.data
                            console.log(json)
                            if (json) {

                                str += `<tr>
                            <td>${i}</td>
                            <td>${json.grounp == null ? '' : json.grounp}</td>
                            <td>${json.dt == null ? '' : json.dt}</td>
                            <td>${json.sheetId == null ? '' : json.sheetId}</td>
                            <td>${json.orderdMateriels.materielName == null ? '' : json.orderdMateriels.materielName}</td>
                            <td>${json.orderdMateriels.materielBrand == null ? '' : json.orderdMateriels.materielBrand}</td>
                            <td>${json.orderdMateriels.materielSpecifications == null ? '' : json.orderdMateriels.materielSpecifications}</td>
                            <td>${json.orderdMateriels.materielModel == null ? '' : json.orderdMateriels.materielModel}</td>
                            <td>${json.orderdMateriels.materielPlace == null ? '' : json.orderdMateriels.materielPlace}</td>
                            <td>${json.orderdMateriels.materielState == null ? '' : json.orderdMateriels.materielState}</td>
                            <td>${json.orderdMateriels.materielUnit == null ? '' : json.orderdMateriels.materielUnit}</td>
                            <td>${json.orderdMateriels.materielAmount == null ? '' : json.orderdMateriels.materielAmount}</td>
                            <td>${json.orderdMateriels.workState == null ? '' : json.orderdMateriels.workState}</td>
                            <td>${json.wordState == null ? '' : json.wordState}</td>
                            <td onclick="ckInfo()"><div class="layui-btn layui-btn-xs">销售出库</div></td>
                            </tr>`
                            }

                        }
                    })

                }
            })
            $('.chukulist').html(str)

        },
        error: function () {
            alert('系统错误！')
        }
    })
    // 查询
    $.ajax({
        url: `${API}/erpOrderd/getListOrderd`,
        type: 'post',
        data: {
            page: 1,
            limit: 10,
            custId: 1
        },
        success: function (res) {
            $.ajax({
                url: `${API}/erpClients/getClientsAll`,
                type: 'get',
                success: function (res1) {

                    var list = res1.data;
                    let arr = res.data.reverse()
                    let str = ''
                    $.each(arr, function (i, n) {
                        str += `<tr>
                    <td>${arr.length - i}</td>`
                        var name = "";
                        $.each(list, function (j, m) {
                            if (n.customerId == m.id) {
                                name = m.customerName;
                            }
                        });
                        str += `<td>${name}</td>
                    <td>${n.sheetId}</td>
                    <td>JFZ${(new Date().getTime())}${i}</td>
                    `
                        if (n.orderdMateriels != null) {
                            str += `<td>${n.orderdMateriels.materielName == null ? '' : n.orderdMateriels.materielName}</td>
                    <td>${n.orderdMateriels.materielSpecifications == null ? '' : n.orderdMateriels.materielSpecifications}</td>
                    <td>${n.orderdMateriels.materielBrand == null ? '' : n.orderdMateriels.materielBrand}</td>
                    <td>${n.orderdMateriels.materielModel == null ? '' : n.orderdMateriels.materielModel}</td>
                    <td>${n.orderdMateriels.materielPlace == null ? '' : n.orderdMateriels.materielPlace}</td>
                    <td>${n.orderdMateriels.materielState == null ? '' : n.orderdMateriels.materielState}</td>
                    <td>${n.orderdMateriels.materielUnit == null ? '' : n.orderdMateriels.materielUnit}</td>
                    <td>${n.orderdMateriels.materielAmount == null ? '' : n.orderdMateriels.materielAmount}</td>`

                        } else {
                            str += `<td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>`
                        }
                        str += `<td> ${n.bManager == null ? '' : n.bManager}</td >
                    </tr >`
                    })
                    $('.lists').append(str)
                }
            })


        }
    })
</script>